Redirect a moved page with a hash file
-
What you'll see
A page is moved, renamed or merged into another page – a service page moves into a new topic folder, two competing pages are consolidated, or a document is replaced by a hub. The old URL is linked from other sites, bookmarked and indexed by search engines, so it must keep working and pass its ranking on to the new address.
Docly has no redirect table in the site configuration, so the redirect has to live at the old path itself.
-
What's actually happening
Two kinds of redirect, with different status codes.
- A
.oldfile at the old path answers HTTP 301 Moved Permanently. When nothing else exists at the requested path, Docly looks for<path>.oldand redirects to the URL written in it (a relative target such as/portaleris expanded to an absolute URL). A 301 is what search engines expect for a permanent move: they transfer the old URL's signals to the target and replace it in the index. docly.redirect(url, { permanent: true })in a hash file answers HTTP 301 Moved Permanently, the same as a.oldfile. Use it for a permanent move when the redirect is easier to keep in code.docly.redirect(url)without the option answers HTTP 302 Found — a temporary redirect — since 15 October 2026. Before that it answered 301 by mistake. Use it when the redirect depends on something (a condition, a parameter) or is not permanent.
A third form needs no code either: a document with the built-in schema Internet Shortcut — a
.urlfile whose content is[InternetShortcut]followed by a lineURL=https://…— answers 301 to that URL when it is requested. Use it for a link that should leave the site, such as a short address for a booking system.Neither is frozen by the hash cache (see Hash files are cached): changing the target takes effect on the next request.
The second argument of
docly.redirectis an options object, not a status code.#docly.redirect("/portaler", 301)#stops the page with an error in the site's console — docly.redirect does not take a status code — and the visitor gets the site's error page. A misspelled option, orpermanentthat is nottrueorfalse, is an error in the same way. Before this, a second argument was ignored silently: the call did not redirect, and the page answered 200 with an empty body. - A
-
What to do
Do – a permanent move:
{ permanent: true }in a hash file at the old path:#docly.redirect("/portaler/salgsportal", { permanent: true })# <!-- 301 -->Or a
.oldfile at the old path whose whole content is the new URL:tjenester/Salgsportaler.old → /portaler/salgsportalThe
.oldfile is only consulted when nothing else exists at the old path, so the old page itself must be gone.Do – a temporary or conditional redirect: the address only, in a hash file at the old path:
#docly.redirect("/portaler/salgsportal")# <!-- 302 -->Don't – a status code as the second argument:
#docly.redirect("/portaler/salgsportal", 301)# <!-- error in the console, no redirect -->Checklist when moving a page:
- If the old URL was served by a document (
Salgsportaler.docly), take a copy withdocly get --rawand delete it before creating the redirect — a document at the path wins, and a.oldfile is never consulted while it exists. - Folder listings built with
docly.getFiles()also return a redirect file. Filter onfileschema(see getFiles returns every file in the folder), or the redirect shows up as an empty card or menu item. - Remove the old URL from the sitemap and add the new one. A sitemap must not list URLs that redirect.
- Update internal links to point straight at the new URL. The redirect is for the outside world; internal links through a redirect cost an extra round trip.
- Verify with
curl -I https://your-domain/old-url: expect301fordocly.redirectwith{ permanent: true }, a.oldfile or a.urlshortcut,302fordocly.redirectwithout it, and the rightLocation.
To move a page into a folder of the same name (a file
kunstig-intelligens.hashbecoming the folderkunstig-intelligens/), no redirect file is needed — see A folder takes precedence over a file with the same name. - If the old URL was served by a document (
Last reviewed 20 Nov 2026